<template>
  <div class="checkPlan_box">
    <div class="checkPlan_top">
      <div class="checkPlan_title">点检计划完成率</div>
      <div class="checkPlan_month">
        <el-select v-model="value" placeholder="请选择" @change="getValue">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
    </div>
    <div v-if="month&&month.length>0" class="echarts_container">
      <div id="accomplish" class="col-md-12  col-sm-12 col-xs-12" style="height:100%" />
      <div id="accomplishColumn" class="col-md-12  col-sm-12 col-xs-12" style="height: 100% " />
    </div>
    <div v-else class="echarts_noData">
      <svg-icon icon-class="暂无数据" />
    </div>
  </div>
</template>

<script>
import { deviceCheckPlanCompletedRatio } from '@/api/equipmentManage/equipmentReport/dataBoard'

export default {
  name: 'LocationDistribution',
  data() {
    return {
      msg: 'fafa',
      options: [{
        value: '1',
        label: '面积图'
      }, {
        value: '2',
        label: '柱状图'
      }],
      value: '1',
      month: ['1'],
      myChart: undefined,
      vertical: undefined
    }
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById('accomplish'))
    this.vertical = this.$echarts.init(document.getElementById('accomplishColumn'))
    this.drawLine()
    this.getList()
    // this.getValue()
  },
  methods: {
    getList() {
      deviceCheckPlanCompletedRatio().then(res => {
        this.month = res.data

        this.$nextTick(() => {
          this.getValue()
          this.drawLine()
        })
      })
    },
    getValue() {
      if (this.value == '1') {
        const myChartline = document.getElementById('accomplish')
        const myVertical = document.getElementById('accomplishColumn')
        myChartline.style.display = 'block'
        myVertical.style.display = 'none'
      } else {
        const myChartline = document.getElementById('accomplish')
        const myVertical = document.getElementById('accomplishColumn')
        myChartline.style.display = 'none'
        myVertical.style.display = 'block'
      }
    },
    drawLine() {
      // const myChart = this.$echarts.init(document.getElementById('accomplish'))
      // const vertical = this.$echarts.init(document.getElementById('accomplishColumn'))
      const monthOne = this.month
      this.myChart.setOption({
        grid: {
          show: false,
          top: '20',
          right: '20',
          bottom: '40',
          left: '80'
        },
        xAxis: {
          type: 'category',
          boundaryGap: true,
          offset: 2,
          data: monthOne.map(item => item.date),
          axisTick: {
            show: false
          },
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            }
          },
          axisLine: {
            show: false
          }
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value}%',
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            },
            margin: 20
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          splitLine: {
            // 坐标轴在 grid 区域中的分隔线。
            show: true,
            lineStyle: {
              color: 'rgba(0, 0, 0, 0.2)'
            }
          }
        },
        series: [
          {
            data: monthOne.map(item => item.completedRatio * 100),
            type: 'line',
            silent: true,
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: 'rgba(120, 166, 255, 1)' // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: 'rgba(255, 255, 255, 1)' // 100% 处的颜色
                  }
                ],
                global: false // 缺省为 false
              }
            },
            itemStyle: {
              normal: {
                color: 'rgba(120, 166, 255, 1)', // "#4AA0FF", //折点颜色
                lineStyle: {
                  color: 'rgba(120, 166, 255, 1)', // "#4AA0FF", //折线颜色
                  width: this.strokeWidth
                }
              }
            },
            lineStyle: {
              normal: {
                width: 3
                // shadowColor: 'rgba(209, 34, 255, 0.26)',
                // shadowBlur: 10,
                // shadowOffsetY: -10
              }
            }
          }
        ]
      })
      this.vertical.setOption({
        grid: {
          show: false,
          top: '20',
          right: '20',
          bottom: '40',
          left: '80'
        },
        color: ['#5AD1FF'],
        xAxis: {
          type: 'category',
          data: monthOne.map(item => item.date),
          axisTick: {
            show: false
          },
          offset: 2,
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            }
          },
          axisLine: {
            show: false
          }
        },
        yAxis: {
          type: 'value',
          // 影藏y轴刻度
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            formatter: '{value}%',
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            },
            margin: 20
          }
        },
        series: [
          {
            data: monthOne.map(item => item.completedRatio * 100),
            silent: true,
            type: 'bar',
            barWidth: 30 // 柱图宽度
          }
        ]
      })
    }
  }
}
</script>

<style lang="less" scoped>
.checkPlan_box{
  width: 100%;
  height: calc(100% - 50px);
}
.checkPlan_top {
  display: flex;
  justify-content: space-between;

  .checkPlan_title {
    font-size: 20px;
    font-weight: bold;
    line-height: 34px;
    letter-spacing: -0.21px;
    color: #333333;
    padding-top: 16px;
    padding-left: 20px;
  }

  .checkPlan_month{
    padding-top: 16px;
    padding-right: 20px;
  }
}
</style>
